home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 14 / CU Amiga Magazine's Super CD-ROM 14 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-09].iso / CUCD / Programming / Mesa-2.2 / src / alpha.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-03-13  |  3.4 KB  |  133 lines

  1. /* $Id: alpha.c,v 1.3 1997/03/13 03:07:53 brianp Exp $ */
  2.  
  3. /*
  4.  * Mesa 3-D graphics library
  5.  * Version:  2.2
  6.  * Copyright (C) 1995-1997  Brian Paul
  7.  *
  8.  * This library is free software; you can redistribute it and/or
  9.  * modify it under the terms of the GNU Library General Public
  10.  * License as published by the Free Software Foundation; either
  11.  * version 2 of the License, or (at your option) any later version.
  12.  *
  13.  * This library is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.  * Library General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU Library General Public
  19.  * License along with this library; if not, write to the Free
  20.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  */
  22.  
  23.  
  24. /*
  25.  * $Log: alpha.c,v $
  26.  * Revision 1.3  1997/03/13 03:07:53  brianp
  27.  * optimized gl_alpha_test() by removing conditional from inside loops
  28.  *
  29.  * Revision 1.2  1996/09/15 14:15:54  brianp
  30.  * now use GLframebuffer and GLvisual
  31.  *
  32.  * Revision 1.1  1996/09/13 01:38:16  brianp
  33.  * Initial revision
  34.  *
  35.  */
  36.  
  37.  
  38. #include "alpha.h"
  39. #include "context.h"
  40. #include "types.h"
  41. #include "dlist.h"
  42. #include "macros.h"
  43.  
  44.  
  45.  
  46. void gl_AlphaFunc( GLcontext* ctx, GLenum func, GLclampf ref )
  47. {
  48.    if (INSIDE_BEGIN_END(ctx)) {
  49.       gl_error( ctx, GL_INVALID_OPERATION, "glAlphaFunc" );
  50.       return;
  51.    }
  52.    switch (func) {
  53.       case GL_NEVER:
  54.       case GL_LESS:
  55.       case GL_EQUAL:
  56.       case GL_LEQUAL:
  57.       case GL_GREATER:
  58.       case GL_NOTEQUAL:
  59.       case GL_GEQUAL:
  60.       case GL_ALWAYS:
  61.          ctx->Color.AlphaFunc = func;
  62.          ctx->Color.AlphaRef = CLAMP( ref, 0.0F, 1.0F );
  63.          ctx->Color.AlphaRefUbyte = (GLubyte) (ctx->Color.AlphaRef
  64.                                               * ctx->Visual->AlphaScale);
  65.          break;
  66.       default:
  67.          gl_error( ctx, GL_INVALID_ENUM, "glAlphaFunc(func)" );
  68.          break;
  69.    }
  70. }
  71.  
  72.  
  73.  
  74.  
  75. /*
  76.  * Apply the alpha test to a span of pixels.
  77.  * In/Out:  mask - current pixel mask.  Pixels which fail the alpha test
  78.  *                 will set the corresponding mask flag to 0.
  79.  * Return:  0 = all pixels in the span failed the alpha test.
  80.  *          1 = one or more pixels passed the alpha test.
  81.  */
  82. GLint gl_alpha_test( GLcontext* ctx,
  83.                      GLuint n, const GLubyte alpha[], GLubyte mask[] )
  84. {
  85.    GLuint i;
  86.    GLubyte ref = ctx->Color.AlphaRefUbyte;
  87.  
  88.    /* switch cases ordered from most frequent to less frequent */
  89.    switch (ctx->Color.AlphaFunc) {
  90.       case GL_LESS:
  91.          for (i=0;i<n;i++) {
  92.         mask[i] &= (alpha[i] < ref);
  93.      }
  94.      return 1;
  95.       case GL_LEQUAL:
  96.          for (i=0;i<n;i++) {
  97.         mask[i] &= (alpha[i] <= ref);
  98.      }
  99.      return 1;
  100.       case GL_GEQUAL:
  101.          for (i=0;i<n;i++) {
  102.         mask[i] &= (alpha[i] >= ref);
  103.      }
  104.      return 1;
  105.       case GL_GREATER:
  106.          for (i=0;i<n;i++) {
  107.         mask[i] &= (alpha[i] > ref);
  108.      }
  109.      return 1;
  110.       case GL_NOTEQUAL:
  111.          for (i=0;i<n;i++) {
  112.         mask[i] &= (alpha[i] != ref);
  113.      }
  114.      return 1;
  115.       case GL_EQUAL:
  116.          for (i=0;i<n;i++) {
  117.         mask[i] &= (alpha[i] == ref);
  118.      }
  119.      return 1;
  120.       case GL_ALWAYS:
  121.      /* do nothing */
  122.      return 1;
  123.       case GL_NEVER:
  124.          /* caller should check for zero! */
  125.      return 0;
  126.       default:
  127.      gl_problem( ctx, "Invalid alpha test in gl_alpha_test" );
  128.          return 0;
  129.    }
  130.    /* Never get here */
  131.    return 1;
  132. }
  133.